package com.longtop.perform.ar.web;

import java.util.Date;
import java.util.HashMap;

import com.longtop.framework.base.BaseAction;
import com.longtop.intelliweb.action.IActionContext;
import com.longtop.intelliweb.action.IInitContext;
import com.longtop.intelliweb.view.Dataset;
import com.longtop.perform.ar.service.AssignService;

public class ArDgAcctListAction extends BaseAction {

	protected final String DATASET_ACCT = "Dataset_Acct";

	/**
	 * 系统共用：初始化调用
	 */
	public void init(IInitContext context) {
		super.init(context);
	}

	public void thisPageInit(IInitContext context) {
	}

	public void getAccts(IActionContext context, boolean isFirst) {
		AssignService assignService = this.getBean(AssignService.BEAN_ID);
		Dataset dsAcct = context.getDataset(DATASET_ACCT);
		HashMap map = new HashMap();
		// 查询条件设置
		String custId = context.getElementValue("T_custId");
		String custName = context.getElementValue("T_custName");

		String mainId = context.getElementValue("T_mainId");
		String acctId = context.getElementValue("T_acctId");

		String downs = context.getElementValue("T_downOpenDate");
		Date downOpenDate = null;
		if (downs != null && !"".equals(downs)) {
			downOpenDate = new Date(Long.parseLong(downs));
		}
		String ups = context.getElementValue("T_upOpenDate");
		Date upOpenDate = null;
		if (ups != null && !"".equals(ups)) {
			upOpenDate = new Date(Long.parseLong(ups));
		}
		String orgCode = context.getElementValue("orgId");
		String isAllocate = context.getElementValue("T_isAllocate");
		String acctType = context.getElementValue("T_acctType");

		map.put("acctId", acctId);
		map.put("acctType", acctType);
		map.put("mainId", mainId);
		map.put("custId", custId);
		map.put("custName", custName);
		map.put("downOpenDate", downOpenDate);
		map.put("upOpenDate", upOpenDate);
		map.put("orgCode", orgCode);
		map.put("isAllocate", isAllocate);

		// 查询的表名
		map.put("tablenames", "T_I1_INFO_DG_ACCT");
		map.put("mastertablename", "T_AR_DG_ACCT");

		// 当前第几页
		if (isFirst) {
			dsAcct.setPageNo(1);
		}

		assignService.queryForPageByIbatis("arAssignSql.selectAcctList", null, map, dsAcct, false);

	}

	public void queryAccts(IActionContext context) {
		getAccts(context, true);
	}

	public void loadAccts(IActionContext context) {
		getAccts(context, false);
	}

}
